import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../pages/Login'
import Home from '../pages/Home'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'hash',
  routes: [
    { path: '/', redirect: '/Login' },
    { path: '/Login', name: 'Login', component: Login },
    { path: '/Home', name: 'Home', component: Home }
  ]
});
router.beforeEach((to, from, next) => {
  if (to.path == '/Login') {
    next()
  } else {
    let token = localStorage.getItem('token');
    if (token === 'null' || !token) {
      next('/Login')
    } else {
      next();
    }
  }
});
export default router;
